home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
LIFE6__
/
PROTO
/
P
/
PD_ABOUT.C
< prev
next >
Wrap
Text File
|
1991-08-16
|
9KB
|
244 lines
/* PD_About_Life */
/* File name: About_Life */
/* Function: Handle a modal dialog */
/* History: 8/16/91 Original by Prototyper 3.0 */
#include "PCommonLife6.h" /* Common */
#include "Common_Life6.h" /* Common */
#include "PUtils_Life6.h" /* General Utilities */
#include "Utils_Life6.h" /* General Utilities */
#include "PD_About_Life.h" /* This file */
#include "About_Life.h" /* The user file */
/* ======================================================= */
static Boolean ExitDialog; /* Flag used to exit the Dialog */
static Point MyPt; /* Current list selection point */
static OSErr MyErr; /* OS error returned */
static DialogPtr GetSelection; /* Pointer to this dialog */
static GrafPtr SavedPort; /* Previous grafport */
/* Prototypes */
/* Filter routine for modal dialog routine */
static pascal Boolean MyFilter (DialogPtr theDialog ,EventRecord *theEvent,short *itemHit);
/* This is an update routine for non-controls in the dialog */
/* This is executed after the dialog is uncovered by an alert */
static void Refresh_Dialog(void); /* Refresh the dialogs non-controls */
/* ======================================================= */
/* Initialize the modal dialog, globals and call users routine */
void I_PD_About_Life()
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
short Index; /* For looping */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem, CTempItem; /* Control handle */
Str255 sTemp; /* Get text entered, temp holding */
short itemHit; /* Get selection */
short temp; /* Get selection, temp holding */
D_Init_About_Life();
} /* End of procedure */
/* ======================================================= */
/* Filter routine for dialog events */
static pascal Boolean MyFilter (theDialog ,theEvent,itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
Point MyPt; /* Current list selection point */
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
short chCode; /* Key entered */
long LTemp; /* Used for time delay */
char MyCmdKey; /* The command key */
Boolean CmdDown; /* Flag for command key used */
Boolean valMyFilter; /* Value to return */
valMyFilter = D_Filter_About_Life(theDialog, theEvent, itemHit);/* Call the user routine */
if ((theEvent->what == updateEvt) && ((WindowPtr)theEvent->message == theDialog))/* Only do on an update */
{
BeginUpdate(theDialog); /* Start the update */
DrawDialog(theDialog); /* Draw the controls */
valMyFilter = TRUE; /* Pass out this special itemHit number */
*itemHit = 32000; /* Our special ID */
}
if (theEvent->what == mouseDown) /* Only do on a mouse click */
{
MyPt = theEvent->where; /* Get the point where the mouse was clicked */
GlobalToLocal(&MyPt); /* Convert global to local */
}
if (theEvent->what == keyDown)
{
chCode = theEvent->message & charCodeMask; /* Get character */
MyCmdKey = (char)chCode; /* Change to ASCII */
CmdDown = ((theEvent->modifiers / cmdKey) != 0);/* Get command key state */
if (CmdDown == TRUE) /* Do if command key was down */
{
if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
{
DlgCut(theDialog);
valMyFilter = TRUE;
}
else if ((MyCmdKey =='c') || (MyCmdKey == 'C'))
{
DlgCopy(theDialog);
valMyFilter = TRUE;
}
else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
{
DlgPaste(theDialog);
valMyFilter = TRUE;
}
}
else if ((chCode == 13) || (chCode == 3)) /* CR or Enter */
{
valMyFilter = TRUE; /* Flag we got a hit */
*itemHit = 1; /* Default for CR */
GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
if (DType == (ctrlItem + btnCtrl)) /* If a button then ... */
{
CItem = (ControlHandle)DItem; /* Make it a controlhandle */
HiliteControl(CItem, 10); /* Hilite it */
LTemp = TickCount() + 15; /* Flash the button for 1/4 second */
do
{}
while (LTemp > TickCount());
HiliteControl(CItem, 0); /* UnHilite it */
}
}
}
return(valMyFilter);
}
/* ======================================================= */
/* ======================================================= */
/* This is an update routine for non-controls in the dialog */
/* This is executed after the dialog is uncovered by an alert */
static void Refresh_Dialog() /* Refresh the dialogs non-controls */
{
Rect rTempRect; /* Temp rectangle used for drawing */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
SetPort(GetSelection); /* Point to our dialog window */
GetDItem(GetSelection,Res_Dlg_Big_Deal,&DType,&DItem,&tempRect);/* Get the item handle */
PenSize(3, 3); /* Change pen to draw thick default outline */
InsetRect(&tempRect, -4, -4); /* Draw outside the button by 1 pixel */
FrameRoundRect(&tempRect, 16, 16); /* Draw the outline */
PenSize(1, 1); /* Restore the pen size to the default value */
D_Refresh_About_Life(GetSelection); /* Call user refresh routine */
}
/* ======================================================= */
void PD_About_Life()
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
short Index; /* For looping */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
ControlHandle CTempItem; /* temp Control handle */
Str255 sTemp; /* Get text entered, temp holding */
short itemHit; /* Get selection */
short temp; /* Get selection, temp holding */
GetPort(&SavedPort); /* Get the previous grafport */
GetSelection = GetNewDialog(Res_D_About_Life, NIL, (Ptr)-1);/* Bring in the dialog resource */
tempRect = GetSelection->portRect; /* Get window size, we will now center it */
tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;/* Center vert */
tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
MoveWindow(GetSelection, tempRect.left, tempRect.top, TRUE);/* Now move the window to the proper position */
ShowWindow(GetSelection); /* Open a dialog box */
SelectWindow(GetSelection); /* Lets see it */
SetPort(GetSelection); /* Prepare to add conditional text */
/* Setup initial conditions */
Refresh_Dialog(); /* Draw any Lists, lines, or rectangles */
ExitDialog = FALSE; /* Do not exit dialog handle loop yet */
D_Setup_About_Life(GetSelection); /* Call user Dialog setup routine */
do /* Start of dialog handle loop */
{
ModalDialog(&MyFilter, &itemHit); /* Wait until an item is hit */
if (itemHit == 32000) /* Check for update */
{
Refresh_Dialog(); /* Draw any Lists, lines, or rectangles*/
EndUpdate(GetSelection); /* End of the update*/
}
else
{
GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);/* Get item information */
CItem = (ControlHandle)DItem; /* Get the control handle */
}
D_Hit_About_Life(GetSelection,itemHit,&ExitDialog);/* Let user handle the item hit */
/* Handle it real time */
if (itemHit ==Res_Dlg_Big_Deal) /* Handle the Button being pressed */
{
ExitDialog = TRUE; /* Close this dialog, exit */
}
}
while (ExitDialog == FALSE); /* Handle dialog items until exit selected */
D_Exit_About_Life(GetSelection); /* Exiting the modal dialog */
SetPort(SavedPort); /* Restore the previous grafport */
DisposDialog(GetSelection); /* Flush the dialog out of memory */
} /* End of procedure */